package clases.academico;

import CapaDatos.DataSource;
import CapaDatos.Sql;
import clases.incio.ButtonEditor;
import clases.incio.ButtonRenderer;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Jose Daniel
 */
public class Familiar extends Alumno {

    private String cedulaFamiliar;
    private String ocupacion;
    private String mail;
    private String lugartrabajo;
    private String parentezco;
    private int hijos;
    private String representante;
    private String factura;

    private String sql;
    private final DataSource dt;

    public Familiar() {
        dt = new DataSource();

    }

    public String getCedulaFamiliar() {
        return cedulaFamiliar;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public void setCedulaFamiliar(String cedulaFamiliar) {
        this.cedulaFamiliar = cedulaFamiliar;
    }

    public String getOcupacion() {
        return ocupacion;
    }

    public void setOcupacion(String ocupacion) {
        this.ocupacion = ocupacion;
    }

    public String getLugartrabajo() {
        return lugartrabajo;
    }

    public void setLugartrabajo(String lugartrabajo) {
        this.lugartrabajo = lugartrabajo;
    }

    public String getParentezco() {
        return parentezco;
    }

    public void setParentezco(String parentezco) {
        this.parentezco = parentezco;
    }

    public int getHijos() {
        return hijos;
    }

    public void setHijos(int hijos) {
        this.hijos = hijos;
    }

    public String getRepresentante() {
        return representante;
    }

    public void setRepresentante(String representante) {
        this.representante = representante;
    }

    public String getFactura() {
        return factura;
    }

    public void setFactura(String factura) {
        this.factura = factura;
    }

    public void listarOcupacion(JComboBox combo) {
        sql = "SELECT DISTINCT OCUPACION FROM FAMILIAR";
        combo.removeAllItems();
        combo.addItem("--Seleccione--");
        Sql.getConsulta(sql, dt);
        while (dt.next()) {
            combo.addItem(dt.getString(1));
        }
    }

    public boolean guardarFamiliar() {
        this.guardarPersona();
        sql = "INSERT INTO FAMILIAR VALUES('" + this.cedulaFamiliar
                + "','" + lugartrabajo + "','" + ocupacion + "', '"
                + mail + "', " + hijos + ")";
        return Sql.insertar(sql);
    }

    public boolean guardarFamiliarAlumno() {
        return Sql.insertar("INSERT INTO FAMILIARALUMNO VALUES('" + this.cedulaFamiliar
                + "', '" + this.getCedulaAlumno() + "', " + this.representante + ", "
                + this.factura + ", '" + parentezco + "')");
    }

    protected void eliminarFamiliar() {
        sql = "DELETE FROM FAMILIAR WHERE CEDULAFAMILIAR "
                + "IN (SELECT CEDULAFAMILIAR "
                + "FROM FAMILIARALUMNO WHERE CEDULARUC='" + this.getCedulaRuc() + "')";
        Sql.eliminar(sql);
        sql = "DELETE FROM PERSONA CASCADE WHERE CEDULARUC                           \n"
                + "IN (SELECT FAMILIAR.CEDULAFAMILIAR FROM FAMILIAR JOIN FAMILIARALUMNO \n"
                + "ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR WHERE CEDULARUC='1')";
        this.eliminarPersona();
    }

    public void eliminarFamiliarAlumno() {
        sql = "DELETE FROM FAMILIARALUMNO WHERE CEDULAFAMILIAR "
                + "IN (SELECT CEDULAFAMILIAR FROM FAMILIAR "
                + "JOIN PERSONA ON CEDULAFAMILIAR=CEDULARUC)AND "
                + "CEDULARUC ='" + this.getCedulaRuc() + "'";
        //System.out.println(sql);
        Sql.eliminar(sql);
        // this.eliminarFamiliar();
    }

    public void actualizarFamiliar() {
        this.actualizarPersona();
        sql = "UPDATE FAMILIAR SET LUGARTRABAJO='" + this.lugartrabajo + "',  "
                + "OCUPACION='" + this.ocupacion + "', "
                + "MAIL='" + this.mail + "', NUMEROHIJOS=" + this.hijos + " "
                + "WHERE CEDULAFAMILIAR='" + this.cedulaFamiliar + "'";
        Sql.actualizar(sql);
    }

    public boolean ExistenciaFamiliar(String cedula) {
        sql = "SELECT * FROM FAMILIAR JOIN PERSONA "
                + "ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR "
                + "WHERE FAMILIAR.CEDULAFAMILIAR='" + cedula + "'";
        return Sql.isExiste(sql);
    }

    public boolean ExistenciaFamiliarAlumno(String cedulaAlumno, String cedulaFamiliar) {
        sql = "SELECT * FROM FAMILIARALUMNO "
                + "WHERE EXISTS (SELECT CEDULAFAMILIAR FROM FAMILIAR "
                + "WHERE FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR) "
                + "AND CEDULARUC='" + cedulaAlumno + "' AND CEDULAFAMILIAR='" + cedulaFamiliar + "'";
        System.out.println(sql);
        return Sql.isExiste(sql);
    }

    /*public boolean ExistenciaFamiliarActualizar(String cedula){
     if(!cedula.equals(this.getCedulaRuc())){
     sql="SELECT * FROM FAMILIAR JOIN PERSONA "
     + "ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR "
     + "WHERE FAMILIAR.CEDULAFAMILIAR='"+cedula+"' AND FAMILIAR.CEDULAFAMILIAR!='"+this.getCedulaRuc()+"'";   
     return Sql.isExiste(sql);
     }
     else return false;
     }*/
    public String SqlGeneralFamiliar() {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC \n"
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n"
                + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        System.out.println(sql);
        return sql;
    }

    public String SqlNombreFamiliar(String nombre) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) "
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR "
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR "
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE NOMBRE LIKE '" + nombre + "%' "
                + "ORDER BY(CONCAT(APELLIDO,' ',NOMBRE)";

        return sql;
    }

    public String SqlApellidoFamiliar(String apellido) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) "
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR "
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR "
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE APELLIDO LIKE '" + apellido + "%'"
                + "ORDER BY(CONCAT(APELLIDO,' ',NOMBRE)";

        return sql;
    }

    public String SqlCedulaFamiliar(String cedula) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC WHERE FAMILIAR.CEDULAFAMILIAR LIKE ('" + cedula + "%') \n"
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n"
                  + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        
        return sql;
    }

    public String SqlFamiliar(String familiar) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE CONCAT(APELLIDO,' ',NOMBRE) LIKE ('" + familiar + "%')\n "
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n "
                + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        return sql;
    }

    public String SqlFamiliarAlumno(String alumno) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE (SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) LIKE ('" + alumno + "%')\n "
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n "
               + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        return sql;
    }

    public String SqlFamiliarParentezco(String parentezco) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE PARENTEZCO = '" + parentezco + "'\n "
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n "
                 + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        return sql;
    }

    public String SqlFamiliarRepresentante(String representante) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE REPRESENTANTE = " + this.TextoaBoleano(representante) + "\n "
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n "
                 + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        return sql;
    }

    public String SqlFamiliarFactura(String factura) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, CONCAT(APELLIDO,' ',NOMBRE) AS FAMILIAR, \n"
                + "(SELECT CONCAT(APELLIDO,' ',NOMBRE) FROM PERSONA \n"
                + "WHERE CEDULARUC IN(SELECT CEDULARUC FROM ALUMNO \n"
                + "WHERE PERSONA.CEDULARUC=ALUMNO.CEDULARUC AND ALUMNO.CEDULARUC \n"
                + "IN(SELECT CEDULARUC FROM FAMILIARALUMNO \n"
                + "WHERE FAMILIARALUMNO.CEDULARUC=ALUMNO.CEDULARUC))) AS ALUMNO, \n"
                + "PARENTEZCO, REPRESENTANTE, FACTURA, \n"
                + "COUNT(FAMILIARALUMNO.CEDULARUC) AS HIJOSINTITUCION, TELEFONO, OCUPACION, DIRECCION  \n"
                + "FROM FAMILIAR JOIN PERSONA ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR \n"
                + "JOIN FAMILIARALUMNO ON FAMILIAR.CEDULAFAMILIAR=FAMILIARALUMNO.CEDULAFAMILIAR \n"
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE FACTURA = '" + this.TextoaBoleano(factura) + "'\n "
                + "GROUP BY FAMILIAR.CEDULAFAMILIAR, ALUMNO, NOMBRE, APELLIDO, \n "
                + "TELEFONO, DIRECCION, OCUPACION, REPRESENTANTE, PARENTEZCO, FACTURA ORDER BY(FAMILIAR)";
        return sql;
    }

    public void ConsultaFamiliar(DefaultTableModel modelo, JTable tabla, String sql, JLabel Lpaginatotal, JLabel Lpagina, int pagina) {
        modelo = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int fila, int columna) {
                return false; //Con esto conseguimos que la tabla no se pueda editar
            }
        };
        tabla.setModel(modelo);
        modelo.addColumn("Nº");
        modelo.addColumn("CEDULA");
        modelo.addColumn("FAMILIAR");
        modelo.addColumn("ALUMNO");
        modelo.addColumn("PARENTEZCO");
        modelo.addColumn("REPRESENTANTE");
        modelo.addColumn("FACTURA");
        modelo.addColumn("HIJOS INSTITUCION");
        modelo.addColumn("TELEFONO");
        modelo.addColumn("OCUPACION");
        modelo.addColumn("DIRECION");
        DefaultTableCellRenderer centrar = new DefaultTableCellRenderer();
        centrar.setHorizontalAlignment(SwingConstants.CENTER);
        tabla.getColumnModel().getColumn(0).setCellRenderer(centrar);
        tabla.getColumnModel().getColumn(7).setCellRenderer(centrar);
        tabla.getColumnModel().getColumn(6).setCellRenderer(centrar);
        tabla.getColumnModel().getColumn(5).setCellRenderer(centrar);
        TableColumn columna = new TableColumn();
        columna = tabla.getColumnModel().getColumn(0);
        columna.setPreferredWidth(5);
        columna = tabla.getColumnModel().getColumn(1);
        columna.setPreferredWidth(50);
        columna = tabla.getColumnModel().getColumn(2);
        columna.setPreferredWidth(150);
        columna = tabla.getColumnModel().getColumn(3);
        columna.setPreferredWidth(150);
        columna = tabla.getColumnModel().getColumn(4);
        columna.setPreferredWidth(50);
        columna = tabla.getColumnModel().getColumn(5);
        columna.setPreferredWidth(60);
        columna = tabla.getColumnModel().getColumn(6);
        columna.setPreferredWidth(30);
        columna = tabla.getColumnModel().getColumn(7);
        columna.setPreferredWidth(80);
        columna = tabla.getColumnModel().getColumn(8);
        columna.setPreferredWidth(60);
        columna = tabla.getColumnModel().getColumn(9);
        columna.setPreferredWidth(100);
        columna = tabla.getColumnModel().getColumn(10);
        columna.setPreferredWidth(150);

        sql = objPaginacion.getPaginacion(sql, pagina, 50);
        Sql.getConsulta(sql, dt);
        String[] fila;
        int n = (pagina * 50) - 49;
        while (dt.next()) {
            fila = new String[11];
            fila[0] = Integer.toString(n);
            fila[1] = dt.getString(1);
            fila[2] = dt.getString(2);
            fila[3] = dt.getString(3);
            fila[4] = dt.getString(4);
            fila[5] = this.CambiarBoolean(dt.getString(5));
            fila[6] = this.CambiarBoolean(dt.getString(6));
            fila[7] = dt.getString(7);
            fila[8] = dt.getString(8);
            fila[9] = dt.getString(9);
            fila[10] = dt.getString(10);
            modelo.addRow(fila);
            n++;
        }
        objPaginacion.actualPagina(Lpagina);
        objPaginacion.totalPaginas(Lpaginatotal);
        tabla.getSelectionModel().setSelectionInterval(0, 0);
    }

    public void BuscarFamiliar(DefaultTableModel modelo, JTable tabla, String sql, JLabel Lpaginatotal, JLabel Lpagina, int pagina) {
        modelo = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int fila, int columna) {
                return false; //Con esto conseguimos que la tabla no se pueda editar
            }
        };
        tabla.setModel(modelo);
        modelo.addColumn("Nº");
        modelo.addColumn("CEDULA");
        modelo.addColumn("FAMILIAR");

        DefaultTableCellRenderer centrar = new DefaultTableCellRenderer();
        centrar.setHorizontalAlignment(SwingConstants.CENTER);
        tabla.getColumnModel().getColumn(0).setCellRenderer(centrar);
        TableColumn columna = new TableColumn();
        columna = tabla.getColumnModel().getColumn(0);
        columna.setPreferredWidth(15);
        columna = tabla.getColumnModel().getColumn(1);
        columna.setPreferredWidth(100);
        columna = tabla.getColumnModel().getColumn(2);
        columna.setPreferredWidth(400);
        sql = objPaginacion.getPaginacion(sql, pagina, 25);
        Sql.getConsulta(sql, dt);
        String[] fila;
        int n = (pagina * 25) - 24;
        while (dt.next()) {
            fila = new String[3];
            fila[0] = Integer.toString(n);
            fila[1] = dt.getString(1);
            fila[2] = dt.getString(2);

            modelo.addRow(fila);
            n++;
        }
        objPaginacion.actualPagina(Lpagina);
        objPaginacion.totalPaginas(Lpaginatotal);
        tabla.getSelectionModel().setSelectionInterval(0, 0);
    }

    public void llenardatosFamiliarAlumno(DefaultTableModel modelo, JTable tabla) {
        sql = "SELECT FAMILIAR.CEDULAFAMILIAR, NOMBRE, APELLIDO, TELEFONO, DIRECCION, "
                + "IDCIUDAD, LUGARTRABAJO, OCUPACION, MAIL, NUMEROHIJOS, PARENTEZCO, REPRESENTANTE, "
                + "FACTURA FROM PERSONA JOIN FAMILIAR ON PERSONA.CEDULARUC=FAMILIAR.CEDULAFAMILIAR "
                + "JOIN FAMILIARALUMNO ON FAMILIARALUMNO.CEDULAFAMILIAR=FAMILIAR.CEDULAFAMILIAR "
                + "JOIN ALUMNO ON ALUMNO.CEDULARUC=FAMILIARALUMNO.CEDULARUC "
                + "WHERE ALUMNO.CEDULARUC='" + this.getCedulaRuc() + "'";
        Sql.getConsulta(sql, dt);
        String[] fila;

        while (dt.next()) {
            fila = new String[13];
            fila[0] = dt.getString(1);
            fila[1] = dt.getString(2);
            fila[2] = dt.getString(3);
            fila[3] = dt.getString(4);
            fila[4] = dt.getString(5);
            fila[5] = this.SacarCiudad(dt.getInt(6));
            fila[6] = dt.getString(7);
            fila[7] = dt.getString(8);
            fila[8] = dt.getString(9);
            fila[9] = dt.getString(10);
            fila[10] = dt.getString(11);
            fila[11] = this.CambiarBoolean(dt.getString(12));
            fila[12] = this.CambiarBoolean(dt.getString(13));

            tabla.getColumnModel().getColumn(13).setCellRenderer(new ButtonRenderer());
            tabla.getColumnModel().getColumn(13).setCellEditor(
                    new ButtonEditor(new JCheckBox(), modelo, tabla));
            modelo.addRow(fila);
        }
    }

    public void llenardatosFamiliar() {
        sql = "SELECT LUGARTRABAJO, OCUPACION, MAIL, NUMEROHIJOS, PARENTEZCO, FACTURA, REPRESENTANTE "
                + "FROM FAMILIAR JOIN FAMILIARALUMNO ON FAMILIARALUMNO.CEDULAFAMILIAR=FAMILIAR.CEDULAFAMILIAR "
                + "WHERE FAMILIAR.CEDULAFAMILIAR='" + this.getCedulaRuc() + "'";
        Sql.getConsulta(sql, dt);
        while (dt.next()) {
            this.lugartrabajo = dt.getString(1);
            this.ocupacion = dt.getString(2);
            this.mail = dt.getString(3);
            this.hijos = Integer.parseInt(dt.getString(4));
            this.parentezco = dt.getString(5);
            this.factura = this.CambiarBoolean(dt.getString(6));
            this.representante = this.CambiarBoolean(dt.getString(7));
        }
    }

    public String CambiarBoolean(String dato) {
        if (dato.equals("t")) {
            return "SI";
        } else {
            return "NO";
        }
    }

    public Boolean TextoaBoleano(String dato) {
        switch (dato) {
            case "SI":
                return true;
            case "NO":
                return false;
        }
        return null;
    }
}
